<?php

class Search_Types {
	private $types = array(
	'doc' => true,
	'image' => true,
	'file' => true,
	'link' => true,
	'review' => true,
	'issue' => true,
	'vote' => true,
	'comment' => true,
	'quest' => true,
	);

	private $rh;
	private $store;

	private $typesInstances;

	public function __construct( $rh, $store ) {
		$this->rh = $rh;
		$this->store = $store;
	}

	public function getListTypes() {
		return array_keys($this->types);
	}

	public function getType( $typeKey ) {
		if ( isset($this->types[$typeKey]) ) {
			return $this->types[$typeKey];
		} else {
			return array();
		}
	}

	public function getTypeParser( $ftype ) {
		if ( empty($ftype) ) {
			return false;
		}
		$type = substr($ftype, 1);

		$className = 'Search_' . ucfirst(strtolower($type)) . 'Type';

		if ( !isset($this->typesInstances[$className]) ) {
			$use = $this->rh->useClass($className);
			if ( !$use ) {
				$this->typesInstances[$className] = false;
			} else {
				$this->typesInstances[$className] = new $className($this->rh, $this->store);
			}
		}

		return $this->typesInstances[$className];
	}
}
